/**
 * @(#)Utente.java
 *
 * Utente application
 *
 * @author Celani Mauro
 * @version 1.00 2013/9/15
 */

import java.security.MessageDigest;
 
public abstract class Utente {
    
    protected String username;
    protected byte[] password;
    protected String residenza;
    protected String email;
    
    protected Utente(String user){
    	this(user, "prova", "via delle rose", "prova@prova.it");
    }
    
    protected Utente(String username, String pwd, String residenza, String email){
    	setUsername(username);
    	setPassword(pwd);
    	setResidenza(residenza);
    	setEmail(email);
    }
    
    public String getUsername()	{ return username; }
    public byte[] getPassword()	{ return password; }
    public String getResidenza(){ return residenza; }
    public String getEmail()	{ return email; }
    
    public void setUsername(String username)	{ this.username = username; }
    public void setResidenza(String residenza)	{ this.residenza = residenza; }
    public void setEmail(String email)			{ this.email = email; }
    
    public void setPassword(String pwd){
    	try{
    		
    		MessageDigest md = MessageDigest.getInstance("MD5");
  			this.password = md.digest(pwd.getBytes("UTF-8"));
  			
    	}catch(Exception e){
    		System.out.println("ERROR: Can't calculate md5.");
    	}
    	
    }
    
}
